<?php

namespace plugin\ycMassage\process;

use plugin\ycMassage\app\model\MassageWinnerlookPrivacy;
use plugin\ycMassage\utils\enum\WinnerlookState;
use plugin\ycMassage\utils\Yunxin;

class Winnerlook
{
    public function unbind()
    {
        try {
            $MassageOrders = MassageWinnerlookPrivacy::where(['state' => WinnerlookState::BINDING['value']])->whereTime('unbind_time', '<', date('Y-m-d H:i:s'))->select();
            foreach ($MassageOrders as $item) {
                try {
                    $Yunxin = new Yunxin($item->saas_appid);
                    $data = [
                        'middleNumber' => $item->tel,
                        'bindNumberA' => $item->bind_number_a,
                        'bindNumberB' => $item->bind_number_b,
                        'mode' => '0'
                    ];
                    $Yunxin->middleNumberUnbind($data);
                } catch (\Throwable $th) {
                    p([$th->getMessage(), $th->getLine(), $th->getFile()], 'MassageWinnerlookUnbind');
                }
                $item->state = WinnerlookState::YES['value'];
                $item->alias_id = null;
                $item->bind_number_a = null;
                $item->bind_number_b = null;
                $item->unbind_time = null;
                $item->save();
            }
        } catch (\Throwable $th) {
            p([$th->getMessage(), $th->getLine(), $th->getFile()], 'MassageWinnerlookExpire');
        }
    }
}
